package com.data.center.controller;

import com.data.center.exception.ResultBody;
import com.data.center.service.RegionDivisionRelationService;
import com.data.center.util.ExcelToListUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Li_Jx
 * @description:
 * @date 2023/9/10 14:16
 */
@RestController
@RequestMapping("/regionDivisionRelation")
@Slf4j
public class RegionDivisionRelationController {

    @Autowired
    private RegionDivisionRelationService regionDivisionRelationService;
    /**
     * @description 将excel文件中的数据，更新到region_division_relation表中，region_code和division_code都相同的不更新
     * @输入数据 excel包含两列，第一列为中文大区名(西部,港澳台,东部,中部,东北),第二列为省/直辖市名(例如北京市，湖北省)，省/直辖市之间按照英文逗号分隔，详情参考source/AdminDivision/regionDivisionRelation.xlsx
     * @param filePath
     * @return ResultBody
     * @author Li_Jx
     * @Date 2023/9/10 14:21
     */
    @PutMapping("/updateFromExcel")
    public ResultBody updateFromExcel(String filePath){
        List<String> stringList = ExcelToListUtils.parseExcel(filePath);
        if(stringList.isEmpty()){
            return ResultBody.error("文件内容为空");
        }
        regionDivisionRelationService.updateFromExcel(stringList);
        return ResultBody.success();
    }
}
